package com.zpf.web.servlet;

import com.alibaba.fastjson.JSON;
import com.zpf.pojo.GoodsType;
import com.zpf.service.GoodsTypeService;
import com.zpf.service.impl.GoodsTypeServiceImpl;
import com.zpf.service.GoodsTypeService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/goodstypeservlet")
public class GoodstypeServlet extends BaseServlet {

     GoodsTypeService goodsTypeService = new GoodsTypeServiceImpl();

    public void goodstypelist(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //查询一级分类列表
        List<GoodsType> goodsTypes = goodsTypeService.findTypeListByLevel(1);
        //把集合转换为son字符串
        Object json = JSON.toJSON(goodsTypes);
        //返回到前端
        response.setCharacterEncoding("utf-8");
        response.getWriter().print(json);
    }
}
